#include "LoadMessage.h"

LoadMessage ::LoadMessage (const QString &text, int timeSec, QWidget *parent):
    QDialog(parent)
{
    this->qr = qr;
    this->outTime = timeSec;
    this->nowTime = 0;

    //背景窗口设置
    this->setAttribute(Qt::WA_TranslucentBackground, true);     //设置窗体透明
    this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);   //设置无边框


    //加载显示窗口
    widgetPtr = new QWidget(this);
    //widgetPtr->setGeometry(mw->width()-(561*1.5),mw->width()-(206*1.5), 561,206);
    widgetPtr->setStyleSheet(QString("QWidget{background:#F6FBFF;border-radius:4px;}"));

    //设置显示窗口带背景阴影
    shadow = new QGraphicsDropShadowEffect(this);//实例阴影shadow
    shadow->setOffset(0, 0);                //设置阴影偏移
    shadow->setColor(QColor("#444444"));    //设置阴影颜色
    shadow->setBlurRadius(18);              //设置阴影圆角
    widgetPtr->setGraphicsEffect(shadow);   //给嵌套QWidget设置阴影

    //设置背景窗口与显示窗口布局-格栅布局
    gridLayout = new QGridLayout(this);
    gridLayout->addWidget(widgetPtr);
    gridLayout->setMargin(20);      //给布局器设置边距,设置宽度为阴影的宽度
    this->setLayout(gridLayout);

    //窗口子控件加载，加载gif显示
    QLabel *labGif = new QLabel(widgetPtr);
    QMovie *movie = new QMovie(this);

    movie->setFileName("D:/Project/qtProject/gobang/images/load.gif");
    //movie->setScaledSize(labGif->size());   //自动缩放
    labGif->setMovie(movie);
    movie->start();

    //加载显示的主体内容
    labText = new QLabel(text,widgetPtr);
    //labText->setMinimumSize(300,200);
    labText->setWordWrap(true); //自动换行
    labText->setStyleSheet(QString("QLabel{font:20px Microsoft YaHei;}"));

    //子控件布局
    QHBoxLayout *hBoxLayout = new QHBoxLayout(widgetPtr);
    hBoxLayout->addSpacing(70);
    hBoxLayout->addWidget(labGif);
    hBoxLayout->addWidget(labText);
    hBoxLayout->addSpacing(30);

    this->show();

    net = new net_pthread(timeSec);
    net->start();

    connect(net,&net_pthread::trigger_main, this,&LoadMessage::run);
}

void LoadMessage::run()
{
    nowTime++;

    labText->setText("正在请求...   "+QString::number(nowTime));
    create_post();
    qDebug()<<nowTime;
}
